package com.example.mywechat;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class friendadaptor extends RecyclerView.Adapter<friendadaptor.myviewholder> {
//需要的参数
    private List<friendbean> list;
    private Context context;
    private View inflater;//压缩视图用
//创建viewholder
    static class myviewholder extends RecyclerView.ViewHolder{
        ImageView friendImg;
        TextView friendTextView;
        public myviewholder(@NonNull View itemView) {
            super(itemView);
            friendImg=itemView.findViewById(R.id.friendImageView);
            friendTextView=itemView.findViewById(R.id.friendTextView);

        }
    }
    public friendadaptor(List<friendbean>list2) {
        this.list=list2;
    }



    @NonNull

    @Override
    //创建并初始化 ViewHolder 及其关联的 View，但不会填充视图的内容
    public myviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friend, parent, false);
        //将子项的布局通过LayoutInflater引入
        final myviewholder holder = new myviewholder(view);
        return holder;
    }


    //此方法会提取适当的数据，并使用该数据填充 ViewHolder 的布局
    @Override
    public void onBindViewHolder(@NonNull myviewholder holder, int position) {
        friendbean friendbean=list.get(position);
        //创建实体类对象
        holder.friendImg.setImageResource(friendbean.getPictureId());
        holder.friendTextView.setText(friendbean.getName());

        //将具体值赋与子项对应的控件
    }

    //RecyclerView 调用此方法来获取数据集的大小
    @Override
    public int getItemCount() {
        return list.size();
    }

}
